<template>
  <div class="officeList">
    <div
      v-for="(item,index) in officeSongList"
      :key="item.id"
      class="songItem"
      @dblclick="startPlaySong(item,store)"
      :style="{backgroundColor:index%2===0?'#292929':'#252525'}"
    >
      <div>
        <span :style="{color:index<3&&'#c3479a'}">{{index+1}}</span>
        <span>{{item.name}}</span>
      </div>
      <div>{{item.singer}}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, nextTick, ref, watch } from 'vue'
import axios from '@/http'
import startPlaySong from '@/songPlay.minxin.js'
import { useStore } from 'vuex'
const store = useStore()
const props = defineProps({
  id: {
    type: Number,
    default: 0
  }
})
watch(
  () => props.id,
  val => {
    nextTick(() => getOfficeRankSongList(val))
  },
  {
    immediate: true
  }
)
const officeSongList = ref([])
const getOfficeRankSongList = id => {
  axios
    .get('/playlist/track/all', {
      params: {
        id,
        limit: 5
      }
    })
    .then(res => {
      console.log(res)

      res.data.code === 200 &&
        (officeSongList.value = res.data.songs.map(item => {
          const { picUrl } = item.al
          const { name: singer } = item.ar[0]
          return { ...item, singer, duration: item.dt, picUrl }
        }))
    })
}
</script>

<style scoped lang="less">
.officeList {
  margin-left: 32px;
  height: 100%;
  .songItem {
    font-size: 14px;
    font-weight: bold;
    color: #a3a3a3;
    display: flex;
    height: 40px;
    line-height: 40px;
    justify-content: space-between;
    border-radius: 4px;
    padding: 0 16px;
    &:hover {
      background-color: #2d2d2d !important;
      cursor: pointer;
    }
    div {
      color: #666;
      span {
        margin: 0 10px;
        &:nth-child(2) {
          color: #a3a3a3;
        }
      }
    }
  }
}
</style>